package com.xjl.shujujiegou;

/**
 * @描述：
 * @作者： 许JIAN林
 */
public class ArrQueue {
    private int start ;
    private int end;
    private int size;
    private int[] arr;

    public ArrQueue(int len){
        arr = new int[len];
        start = 0;
        end = 0;
        size = 0;
    }
    public void push(int num) throws Exception {
        if (size == arr.length){
            throw new Exception("队列已满！");
        }
        size++;
        arr[end] = num;
        end = end == arr.length -1 ? 0 :end + 1;
    }
    public int pop() throws Exception {
        if (size == 0){
            throw new Exception("队列已空！");
        }
        size--;
        int flag = arr[start];
        start = start == arr.length -1 ? 0 :start + 1;
        return flag;
    }
    public Integer peek() throws Exception {
        if (size == 0){
            return null;
        }
        return arr[start];
    }
}
